package com.jnu.student;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

//    //private EnglishClickListener listener;
//    private TextView textViewHello;
//    private TextView textViewWorld;
//    private Button buttonChange;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main); //布局

        TextView textViewHello = findViewById(R.id.textView_hello);
        TextView textViewWorld = findViewById(R.id.textView_world);

        Button buttonChange = findViewById(R.id.button_change);
        buttonChange.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View clickedButtonView) {
                String textViewHello_string = textViewHello.getText().toString();
                String textViewWorld_string = textViewWorld.getText().toString();
                textViewHello.setText(textViewWorld_string);
                textViewWorld.setText(textViewHello_string);
            }
        });
    }

/*
        String strHelloWorld = textViewHelloWorld.getText().toString();  //一个字符串资源,资源名称获得字符串
        Log.i("MainActivity", strHelloWorld);
        textViewHelloWorld.setText("你好Android");

        textViewHelloWorld.setText(R.string.text);
        String strHelloWorld2 = this.getResources().getText(R.string.text).toString();
        Log.i("MainActivity", strHelloWorld2);
        textViewHelloWorld.setText(strHelloWorld);
        请编辑一个字符串资源"你好Android",并通过资源名称获得字符串,设置到textview中
        TextView textViewHelloWorld = this.findViewById(R.id.text_view_hello_world);  //获取TextView控件对象
        String string_text = this.getString(R.string.text2);  //通过资源名称获得字符串
        textViewHelloWorld.setText(string_text);              //将字符串设置到textview中
*/




/*
        textViewHello = findViewById(R.id.textView_hello);
        textViewWorld = findViewById(R.id.textView_world);
        buttonChange = findViewById(R.id.button_change);

        listener = new EnglishClickListener();
        buttonChange.setOnClickListener(listener);
    }

    private class EnglishClickListener implements View.OnClickListener{

        @Override
        public void onClick(View clickedButtonView) {
            String textViewHello_string = textViewHello.getText().toString();
            String textViewWorld_string = textViewWorld.getText().toString();
            textViewHello.setText(textViewWorld_string);
            textViewWorld.setText(textViewHello_string);
        }
    }
*/


    /*
    private class EnglishClickListener implements View.OnClickListener{

        @Override
        public void onClick(View clickedButtonView) {
//            textViewHelloWorld.setText(R.string.english);
            textViewHelloWorld.setText(((Button)clickedButtonView).getText());
            Log.v("test", ((Button)clickedButtonView).getText().toString());

        }
    }

    private class ChangeClickListener implements View.OnClickListener{

        @Override
        public void onClick(View clickedButtonView) {
            if (clickedButtonView == ) {
                textViewHelloWorld.setText(R.string.chinese);
            }
            else if(clickedButtonView == buttonEnglish){
                textViewHelloWorld.setText(R.string.english);
            }
        }
    }
*/
}